#include "IIR.h"
#include "lang/StringFormat.hpp"
using namespace yzrilyzr_lang;
using namespace yzrilyzr_array;
namespace yzrilyzr_dsp{
	String IIR::toString()const{
		return StringFormat::object2string("IIR", aCoeff, bCoeff);
	}
	void IIR::resetMemory(){
		input.fill(0);
		output.fill(0);
	}
	std::shared_ptr<DSP> IIR::cloneDSP(){
		return std::make_shared <IIR>(aCoeff.clone(), bCoeff.clone());
	}
	void IIR::cloneParam(DSP * obj1){
		if(auto other=dynamic_cast<IIR *>(obj1)){
			if(aCoeff == nullptr || aCoeff.length != other->aCoeff.length){
				aCoeff=DoubleArray(other->aCoeff.length);
				this->output.ensureCapacity(aCoeff.length);
			}
			if(bCoeff == nullptr || bCoeff.length != other->bCoeff.length){
				bCoeff=DoubleArray(other->bCoeff.length);
				this->input.ensureCapacity(bCoeff.length);
			}
			for(u_index i=0;i < aCoeff.length;++i){
				aCoeff[i]=other->aCoeff[i];
			}
			for(u_index i=0;i < bCoeff.length;++i){
				bCoeff[i]=other->bCoeff[i];
			}
		}
	}
}